<template>
	<view>
		<cu-custom :bgLinerBorder="true" :isBlack="false">
			<block slot="content">添加车牌号</block>
		</cu-custom>
		<view class="contents">
			<view class="flex justify-space-between align-center scale-1px-bottom p-t-10 p-b-7">
				<view class="f-16 fontBold">
					所属城市
				</view>
				<view class="p-r-5">
					<input type="text" placeholder="请输入" v-model="postData.city" class="f-14 text-right"/>
				</view>
			</view>
			<view class="flex justify-space-between align-center scale-1px-bottom p-t-10 p-b-7">
				<view class="f-16 fontBold">
					车牌号
				</view>
				<view class="p-r-5">
					<input type="text" placeholder="请输入" v-model="postData.num" class="f-14 text-right"/>
				</view>
			</view>
			<view class="flex justify-space-between align-center m-t-15">
				<view class="f-16 fontBold orange">
					设为默认车牌号
				</view>
				<view class="flex align-center p-l-20" @click="changeSel">
					<image :src="postData.sel==1?'/static/img/seled.png':'/static/img/sel.png'" class="sel" mode=""></image>
				</view>
			</view>
		</view>
		<view style="height: 130rpx;"></view>
		<view class="bottom-wrap flex justify-space-around">
			<view class="bottom-btn bottom-btn2" @click="sub()">
				提交
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				postData:{
					city:'',
					num:'',
					sel:0
				},
				id:0
			}
		},
		onLoad(option) {
			if(option.id){
				this.id = option.id;
				this.getInfo();
			}
		},
		methods: {
			changeSel(){
				this.postData.sel = this.postData.sel==1?0:1;
			},
			getInfo(){
				let data = {
					car_num_id:this.id
				}
				this.$http('/apicloud/User/usersCarNumInfo',data).then(res=>{
					if(res.code == 200){
						let datas = res.data;
						this.postData.sel = datas.is_default;
						this.postData.city = datas.city;
						this.postData.num = datas.car_number;
					}
				})
			},
			sub(){
				let data = {
					city:this.postData.city,
					car_number:this.postData.num,
					is_default:this.postData.sel
				}
				if(this.id){
					data.id = this.id;
				}
				this.$http('/apicloud/User/saveUsersCarNum',data).then(res=>{
					if(res.code == 200){
						this.$util.showToast(res.mess);
						setTimeout(()=>{
							uni.navigateBack();
						},1000)
					}else{
						this.$util.showToast(res.mess);
					}
				})
			},
		}
	}
</script>

<style lang="less">
	.sel{
		width: 44rpx;
		height: 44rpx;
	}
	.bottom-wrap {
		box-shadow: 0px -3px 6px rgba(0, 0, 0, 0.07);
		border-radius: 20px 20px 0 0;
		height: 130rpx;
		position: fixed;
		bottom: 0;
		left: 0;
		z-index: 100;
		background: #ffffff;
		width: 100%;
		padding: 15rpx 30rpx 0 30rpx;
	
		.bottom-btn {
			width: 100%;
			height: 76rpx;
			display: flex;
			justify-content: center;
			align-items: center;
			color: #ffffff;
			font-weight: bold;
			border-radius: 60rpx;
		}
	
	
		.bottom-btn2 {
			background: #FF5200;
		}
	}
</style>
